package com.xiaoxin.urlshorter.utils;

import com.xiaoxin.urlshorter.DataDictionary.DataDictionaryItem;
import com.xiaoxin.urlshorter.DataDictionary.XMLDDItemParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;

/**
 * @author jinbo.song
 * @description 数据字典编码转换方法类
 */
public class DataDictionaryUtils {

    private static Logger logger = LoggerFactory.getLogger(DataDictionaryUtils.class);

    private static HashMap<String, List<DataDictionaryItem>> dictMap = new HashMap<>();

    public DataDictionaryUtils() {
    }

    //根据传入的字符分进行取值
    public static HashMap<String, List<DataDictionaryItem>> getDictCode(String dictCode) {
        HashMap<String, List<DataDictionaryItem>> result = new HashMap<>();
        if (dictCode.isEmpty() || dictCode==null) {
            logger.error("输入的数据字典代码不能为空！");

            return result;
        }
        String[] dicCode = dictCode.split(",");

        for (String dCode : dicCode) {
            if (!dictMap.containsKey(dCode)) {
                dictMap.put(dCode, XMLDDItemParser.parseXML(dCode));
            }
            result.put(dCode, dictMap.get(dCode));
        }

        return result;
    }

}
